<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <title>修改密码</title>
    <jsp:include page="easyuiIncludeJS.jsp"/>
</head>
    <script>
        function yzmm() {
            var url = "${pageContext.request.contextPath}/admin/emp/setPwd";
            var password2 = $("#password2").val();
            if(password2.length>20){
                alert('验证密码长度过长');
                return;
            }
            $.post(
                url,
                {
                    "password2": password2
                },
                function (data) {
                    if (data.pwd == 1) {
                        alert(data.msg);
                    }
                    if (data.pwd == 0) {
                        alert(data.msg);
                        $("#yz").hide();
                        $("#div1").show();
                        $("#div2").show();
                        $("#div3").show();
                    }
                },
                "json"
            );
        }

        function savePwd() {
            var password=$("#password").val();
            var password3=$("#password3").val();
            // var patrn = /((?=[\x21-\x7e]+)[^A-Za-z0-9])/;
            // // alert(patrn.test(password));
            // if(patrn.test(password)){
            //     alert('登录密码含有特殊字符');
            //     return false;
            // }else {
            var regular = /\s+/g;
            // alert(regular.test(password));
            if(regular.test(password)){
                alert('登录密码中不能含有空格');
                return false;
            }else{
                if(password==password3){
                    if(password==''||password.length>20){
                        alert("密码长度为一到二十");
                        return false;
                    }else {
                        alert("修改成功,请重新登录");
                        window.close();
                        window.open('${pageContext.request.contextPath}/admin/logins');
                        return true;
                    }
                }else {
                    alert("登录密码与确认密码不一致!");
                    return false;
                }
            }

            // }
        }
    </script>
<body>
<center>
    <form name="form1" id="form1" action="${pageContext.request.contextPath}/admin/emp/login" onsubmit="return savePwd();">
        <br/><br/><br/><br/><br/><br/><br/><br/>
        <div style="margin-bottom:20px" id="yz">
            <label class="label-top">原始密码:</label>
            <input  type="password" name="password2" id="password2"    style="width:530px;">
            <a class="easyui-linkbutton" onclick="yzmm();">验证密码</a>
        </div>
        <div style="display: none" id="div1">
            <label class="label-top">新密码:</label>
            <input   type="password" name="password" id="password" style="width:600px;">
        </div>
        <br/><br/><br/>
        <div style="display: none" id="div2">
            <label class="label-top">确认新密码:</label>
            <input type="password" name="password3" id="password3" style="width:600px;">
        </div>
        <br/><br/><br/>
        <div style="display: none" id="div3">
            <button type="submit"  class="easyui-linkbutton " >保存</button>
        </div>
    </form>
</center>

</body>
</html>
